# coding=utf-8
"""
    @project: qabot
    
    @file： user.py
    @date：2023/9/4 10:57
    @desc:
"""
from django.core import cache
from application.serializers.application_serializers import ApplicationSerializer
from drf_yasg.utils import swagger_auto_schema
from rest_framework.decorators import action
from rest_framework.views import APIView
from rest_framework.views import Request
from common.response import result

from django.utils.translation import gettext_lazy as _
from application.swagger_api.application_api import ApplicationApi
from django.db.models import QuerySet
from common.models.db_model_manage import DBModelManage

user_cache = cache.caches['user_cache']
token_cache = cache.caches['token_cache']

class Info(APIView):
    @action(methods=["GET"], detail=False)
    @swagger_auto_schema(operation_summary=_("Get embedded js"),
                            operation_id=_("Get embedded js"),
                            tags=[_("Application")],
                            manual_parameters=ApplicationApi.ApiKey.get_request_params_api())
    def get(self, request: Request):
        print('参数', request.data)
        # application_setting_model = DBModelManage.get_model('application_setting')
        # application_setting = QuerySet(application_setting_model).filter(
        #             application_id=request.user.id).first()
        # custom_theme = getattr(application_setting, 'custom_theme', {})
        data = {
            'theme': '',
            'icon': '',
            'loginLogo': '',
            'loginImage': '',
            'title': 'WLou',
            'slogan': '',
        }
        return result.success(data=data)
class Update(APIView):
    @action(methods=["POST"], detail=False)
    @swagger_auto_schema(operation_summary=_("Get embedded js"),
                            operation_id=_("Get embedded js"),
                            tags=[_("Application")],
                            manual_parameters=ApplicationApi.ApiKey.get_request_params_api())
    def post(self, request: Request):
        # theme: #00B69D
        # icon: 
        # loginLogo: 
        # loginImage: 
        # title: WLOU
        # slogan: 欢迎使用 WLou 智能知识库问答系统
        data = request.data
        # ConfigSerializer.Create(data = data).save()
        return result.success(data=data)
class Types(APIView):
    @action(methods=["GET"], detail=False)
    @swagger_auto_schema(operation_summary=_("Get embedded js"),
                            operation_id=_("Get embedded js"),
                            tags=[_("Application")],
                            manual_parameters=ApplicationApi.ApiKey.get_request_params_api())
    def get(self, request: Request):
        data = [
            'LDAP',
            'OAUTH2'
        ]
        return result.success(data=data)
class QrType(APIView):
    @action(methods=["GET"], detail=False)
    @swagger_auto_schema(operation_summary=_("Get embedded js"),
                            operation_id=_("Get embedded js"),
                            tags=[_("Application")],
                            manual_parameters=ApplicationApi.ApiKey.get_request_params_api())
    def get(self, request: Request):
        data = [
            'wecom',
            'dingtalk'
        ]
        return result.success(data=data)
        